<template>
	<div class="add-device">
		<div>
			<label>{{$t('Maintenance_Management')}}</label>
			<div></div>
			<button><img /><label>{{$t('Adding_equipment')}}</label></button>
		</div>
		<div>
			<div class="div-1">
				<label class="title">{{$t('kind')}}:</label>
				<el-select class="content" v-model="form.kind" placeholder="$t('kind')">
					<el-option v-for="item in kindList" :label="item" :value="item" />
				</el-select>
				<label class="title">{{$t('Head_Model')}}:</label>
				<el-input class="content" v-model="form.noseCode" />
			</div>

			<div class="div-1">
				<label class="title">{{$t('brand')}}:</label>
				<el-select class="content" v-model="form.brand" placeholder="$t('kind')">
					<el-option v-for="item in brandList" :label="item" :value="item" />
				</el-select>
				<label class="title">{{$t('Purchase_Date')}}:</label>
				<el-date-picker style="margin-left: 20px;" v-model="form.buyDate" type="date" placeholder="$t('Select_date')" />
			</div>

			<div class="div-1">
				<label class="title"></label>
				<el-button @click='addClick'>{{$t('Add')}}</el-button>
			</div>

		</div>


	</div>
</template>

<script>
	import http from "../../js/http/http.js";
	import api from "../../js/http/api.js";
	import CommonUtils from "../../js/common/common-utils.js";
	import Constant from '../../js/common/constant.js'
  import i18n from "@/i18n";
	export default {
		data() {
			return {
				kindList: Constant.DEVICE_KIND,
				brandList: Constant.BRAND_LIST,
				form: {
					kind: null,
					noseCode: null,
					brand: null,
					buyDate: new Date(),
				},
			};
		},
		methods: {
			addClick() {
				console.log(JSON.stringify(this.form));
				if (CommonUtils.isEmpty(this.form.kind)) {
					this.$message.error(i18n.global.t('route.Category_cannot_be_empty'));
					return;
				}
				if (CommonUtils.isEmpty(this.form.noseCode)) {
					this.$message.error(i18n.global.t('route.Category_cannot_be_empty'));
					return;
				}
				if (CommonUtils.isEmpty(this.form.brand)) {
					this.$message.error(i18n.global.t('route.Brand_cannot_be_empty'));
					return;
				}
				this.addDevice();
			},
			addDevice() {
				http.post(api.ADD_DEVICE, {
					adminId: this.$store.state.user.id,
					kind: this.form.kind,
					noseCode: this.form.noseCode,
					brand: this.form.brand,
					buyDate: this.form.buyDate.format('yyyy-MM-dd'),
				}, data => {
					this.$message.success(i18n.global.t('route.Successfully_added'));
					this.$router.go(-1);
				})
			}
		},
		created() {

		}

	};
</script>
<style lang="scss" scoped>
	.add-device {
		color: #444444;
		font-size: 18px;
		padding-right: 20px;
		height: calc(100vh - 100px);
		// overflow: scroll;
		scrollbar-width: none;
		/* firefox */
		-ms-overflow-style: none;
		/* IE 10+ */
		overflow-x: hidden;
		overflow-y: auto;

		>div {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;
		}

		>div:nth-of-type(1) {

			>label:nth-of-type(1) {
				font-weight: 600;
			}

			>div:nth-of-type(1) {
				width: 1px;
				background-color: #cccccc;
				height: 15px;
				margin: 0px 20px;
			}

			>button:nth-of-type(1) {
				background-image: url(../../assets/img/customer-1.png);
				background-repeat: no-repeat;
				background-size: 100% 100%;
				padding: 5px 10px;
				border: 0px;
				display: flex;
				color: #ffffff;
				flex-direction: row;
				align-items: center;
				font-weight: 800;

				>img {
					margin-right: 7px;
					width: 15px;
					height: 15px;
					content: url(../../assets/img/customer-2.png);
				}

			}
		}

		>div:nth-of-type(2) {
			flex-direction: column;
			align-items: flex-start;


			.div-1 {
				display: flex;
				flex-direction: row;
				margin-top: 10px;
				align-items: center;

				.title {
					width: 200px;
					text-align: right;
				}

				.content {
					margin-left: 20px;
					width: 250px;
				}


				>button {
					margin-left: 20px;
					width: 250px;
				}
			}
		}

	}
</style>
